<template>
  <div class="container">
    <div class="container-header">
      <ul>
        <li class="title">猫眼电影</li>
        <li class="nav-item">即将上映</li>
        <li class="all">全部<i class="iconfont">&#xe633;</i></li>
      </ul>
    </div>
    <div @mouseleave="leaveMovie" @mouseenter="enterMovie" class="container-content">
      <div ref="content" class="container-content-contents">
        <div v-for="(item, index) of movieList" :key="index" class="container-content-contents-item">
          <img :src="item.url">
          <div class="content">
            <span class="span-top">{{item.loveCount}}<span class="span-little">人想看</span></span>
            <span class="span-name">{{item.name}}</span>
          </div>
        </div>
      </div>
      <div @click="clickPre" ref="btnPre" class="btn btn-pre">
        <i class="iconfont">&#xe61c;</i>
      </div>
      <div @click="clickNext" ref="btnNext" class="btn btn-next">
        <i class="iconfont">&#xe633;</i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Movie',
  props: {
    movieList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  methods: {
    /** 鼠标移入电影 */
    enterMovie() {
      this.$refs.btnPre.style.opacity = .9
      this.$refs.btnNext.style.opacity = .9
    },
    /** 鼠标移出电影 */
    leaveMovie() {
      this.$refs.btnPre.style.opacity = 0
      this.$refs.btnNext.style.opacity = 0
    },
    /** 点击向下翻页 */
    clickNext() {
      this.$refs.content.style.left = '-1165px'
    },
    /** 点击向回翻页 */
    clickPre() {
      this.$refs.content.style.left = 0
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  width: 1199px;
  padding-right: 7px;
  margin: 0 auto;
  margin-top: 30px;
  &-header {
    width: 100%;
    height: 44px;
    line-height: 44px;
    box-sizing: border-box;
    font-size: 14px;
    color: #fff;
    border-top-right-radius: 5px;
    border-top-left-radius: 5px;
    background: linear-gradient(to right, rgb(250, 60, 104) 2%, rgb(254, 70, 77) 97%) rgb(250, 60, 104);
    ul {
      li {
        display: inline-block;
      }
      .title {
        font-size: 18px;
        margin-left: 13px;
        margin-right: 10px;
        float: left;
        padding: 0 5px;
        position: relative;
        cursor: pointer;
        text-transform: uppercase;
      }
      .nav-item {
        float: left;
        padding: 0 5px;
        position: relative;
        cursor: pointer;
        text-transform: uppercase;
        &::after {
          position: absolute;
          border-top: 6px solid transparent;
          border-left: 4px solid transparent;
          border-right: 4px solid transparent;
          border-bottom: 8px solid #fff;
          content: "";
          width: 11px;
          bottom: 0;
          right: 26px;
          height: 0;
        }
      }
      .all {
        float: right;
        margin-right: 12px;
        .iconfont {
          font-size: 13px;
          color: #fff;
        }
      }
    }
  }
  &-content {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    padding-left: 12px;
    padding-top: 1px;
    &-contents {
      position: relative;
      height: 100%;
      transition: left 0.5s;
      transition-timing-function: ease-out;
      width: 10000000px;
      left: 0px;
      &-item {
        height: 297px;
        width: 214px;
        float: left;
        margin-right: 19px;
        background-size: 100%;
        background-repeat: no-repeat;
        background-position: 50%;
        position: relative;
        img {
          width: 100%;
          height: 100%;
        }
        .content {
          height: 100px;
          width: 100%;
          display: flex;
          flex-direction: column;
          justify-content: flex-end;
          padding-left: 10px;
          position: absolute;
          bottom: 0;
          border-bottom-left-radius: 4px;
          border-bottom-right-radius: 4px;
          background-image: linear-gradient(-180deg, rgba(0,0,0,0.00) 0%, rgba(29,45,55,0.80) 99%);
          span {
            color: #fff;
          }
          .span-top {
            font-size: 16px;
            color: #FD9827;
            font-weight: 500;
            .span-little {
              font-weight: bold;
              font-size: 12px;
            }
          }
          .span-name {
            text-align: left;
            color: #fff;
            margin-bottom: 10px;
            font-size: 16px;
            white-space: nowrap;
            width: 6em;
            overflow: hidden;
            text-overflow: ellipsis;
            font-weight: 500;
          }
        }
      }
    }
    .btn {
      position: absolute;
      width: 40px;
      height: 40px;
      line-height: 40px;
      background: #333;
      position: absolute;
      opacity: 0;
      z-index: 99;
      top: 40%;
      border-radius: 40px;
      text-align: center;
      transition: opacity 0.5s;
      transform: scale(0.95);
      cursor: pointer;
      .iconfont {
        color: #fff;
        font-weight: bold;
      }
    }
    .btn-pre {
      left: 0;
    }
    .btn-next {
      right: 0;
    }
  }
}
</style> 